package com.example.bbs.controller;


import com.example.bbs.provider.GiteeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 登录登出
 */

@Controller
public class AuthorizeController {


    @Autowired
    private GiteeService giteeService;


    /**
     * gitee登录
     *
     * @param code
     * @param response
     * @return
     */
    @GetMapping("/callback")
    public String callBack(@RequestParam(name = "code") String code, HttpServletResponse response) {
        giteeService.login(code, response);
        return "redirect:/";
    }

    /**
     * 注销
     * @return
     */
    @GetMapping("/logout")
    public String exit(HttpServletRequest request, HttpServletResponse response) {
        giteeService.logout(request, response);
        return "redirect:/";
    }
}


